package com.yzkj.siot.vo;

import com.yzkj.siot.domain.SysDict;
import com.yzkj.siot.domain.TenantProduct;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Map;

@Data
public class ProductVO extends TenantProduct {

    /**
     * 数据进制信息
     */
    private SysDict dataBaseInfo;

    /**
     * 数据长度信息
     */
    private String dataLengthInfo;

    public ProductVO() {
    }

    public ProductVO(TenantProduct entity, Map<String, Map<String, SysDict>> dict) {
        BeanUtils.copyProperties(entity, this);
        if (dict == null) {
            this.dataBaseInfo = new SysDict();
            this.dataLengthInfo = "";
            return;
        }
        if (dict.containsKey("data_base") && dict.get("data_base").containsKey(String.valueOf(entity.getDataBase()))) {
            this.dataBaseInfo = dict.get("data_base").get(String.valueOf(entity.getDataBase()));
        } else {
            this.dataBaseInfo = new SysDict();
        }
        if (dict.containsKey("other") && dict.get("other").containsKey("数据长度")) {
            this.dataLengthInfo = entity.getDataLength() + dict.get("other").get("数据长度").getDictLabel();
        } else {
            this.dataLengthInfo = "";
        }
    }
}
